﻿using Assets.Script.Data.Player;
using Assets.Script.Human.Player;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCheck : MonoBehaviour
{
    [SerializeField]private LayerMask groundLayer;
    [SerializeField]private float groundCheckRadius;
    [SerializeField]private Transform groundPos;


    private int nowFrame=0;
    private bool isGround=false;
    private PlayerState playerState;

    private void Awake()
    {
        playerState= GetComponent<PlayerBody>().PlayerState;
    }

    public bool IsGround
    {
        get
        {
            if (nowFrame!=Time.frameCount)
            {
                var cs = Physics.OverlapCapsule(groundPos.position + groundCheckRadius * Vector3.down, groundPos.position + groundCheckRadius * Vector3.up, groundCheckRadius, groundLayer);
                isGround = cs.Length != 0;
                nowFrame = Time.frameCount;
                playerState.Jump = !isGround;
            }
            return isGround;
        }
    }


}
